# Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
# easyAda is licensed under Mulan PubL v2.
# You can use this software according to the terms and conditions of the Mulan PubL v2.
# You may obtain a copy of Mulan PubL v2 at:
#          http://license.coscl.org.cn/MulanPubL-2.0
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PubL v2 for more details.

ifeq (${V},1)
  Q :=
  quiet_make :=
else
  Q :=@
  quiet_make := -s
endif

export Q

# default args
MAKE        := make --no-print-directory $(quiet_make)
export MAKE

# layout
SOURCE_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
BINARY_DIR  = $(SOURCE_DIR)/output

export SOURCE_DIR
export BINARY_DIR


.PHONY: kernel
kernel :
	$(Q)$(MAKE) -f $(SOURCE_DIR)/scripts/kernel.mk kernel

.PHONY: clean
clean :
	$(Q)$(MAKE) -f $(SOURCE_DIR)/scripts/kernel.mk clean
	$(Q)rmdir $(BINARY_DIR) || true

.PHONY: distclean
distclean : clean
	$(Q)$(MAKE) -f $(SOURCE_DIR)/scripts/configure.mk distclean

.PHONY: defconfig
defconfig :
	$(Q)$(MAKE) -f $(SOURCE_DIR)/scripts/configure.mk defconfig

platforms := $(shell $(SOURCE_DIR)/scripts/supported-platforms.sh $(SOURCE_DIR))
platform_defconfigs := $(foreach var,$(platforms),plat_$(var)_defconfig)
.PHONY: $(platform_defconfigs)
$(platform_defconfigs) :
	$(Q)$(MAKE) -f ${SOURCE_DIR}/scripts/configure.mk $@
